;
$(document).ready(function() {
	//点击发送验证码
	mui("body").on("tap", ".yzm", function() {
		$(".phone, .code_input").blur();
		if($(".phone").val()) {
			mui.confirm("将发送验证码至" + $(".phone").val() + "手机", " ", ["发送", "取消"], function(e) {
				if(e.index == 0) {
					require(weburl + model_sendY, "json", "post", {
						token: localStorage.getItem("token"),
						"phone": $(".phone").val()
					}, function(response) {
						mui.alert(response.msg, " ", "关闭", function() {}, "div");
					}, function() { //发送失败
						mui.alert("发送验证码失败，请稍后再试", " ", "关闭", function() {}, "div");
					})
				}
			}, "div")
			return false;
		}
		mui.alert("手机号码不能为空", " ", "关闭", function() {}, "div");
	})

	//点击下一步或者完成
	mui("body").on("tap", ".mui-btn", function() {
		var code = $(".code_input").val();
		var phone = $(".phone").val();
		var pas = $("input[type='password']").eq(0);
		var pas_check = $("input[type='password']").eq(1);
		$(".phone, .code_input").blur();
		$("input[type='password']").blur();
		if(pas.val() && pas_check.val() && code&&phone) { //如果新密码和确认密码都正确
			if(pas.val() == pas_check.val()) {
				console.log(1);
				//在此处写请求
				require(weburl + model_forgotPas, "json", "post", {
					phone: phone,
					verification_code: code,
					password: pas.val(),
					password_confirmation: pas_check.val()
				}, function(response) {
					console.log(JSON.stringify(response));
					if(response.status == "success") {
						mui.alert(response.msg, " ", "确定", function() {
							mui.openWindow("login.html", "login");
						}, "div");
						return false;
					}
					mui.alert(response.msg, " ", "确定", function() {}, "div");
				}, function() {
					console.log(code);
					console.log(phone);
					console.log(pas.val());
					console.log(pas_check.val());
				});
				return false;
			}
			mui.alert("新密码和确认密码不同！", " ", "确定", function() {}, "div");
			return false;

		}else if(!phone){
			mui.alert("手机号码不能为空", " ", "确定", function() {}, "div");
			return false;
		}else if(!code) {
			mui.alert("验证码不能为空", " ", "确定", function() {}, "div");
			return false;
		} else if(!pas) {
			mui.alert("新密码不能为空", " ", "确定", function() {}, "div");
			return false;
		}
		mui.alert("确认密码不能为空", " ", "确定", function() {}, "div");
	})
})